<template>
  <div class="app-container">
    <div>
      <el-button
        type="primary"
        @click="onAdd"
        icon="add"
        v-if="proveType != 2"
        v-hasPermi="['myinvocies:add']"
        >申请开票</el-button
      >
    </div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="案件案号" prop="caseNo">
        <el-input
          v-model="queryParams.caseNo"
          placeholder="请输入案件案号"
          clearable
          class="w200"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票抬头" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入发票抬头"
          clearable
          class="w200"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="审批状态" prop="auditStatus">
        <el-select
          v-model="queryParams.auditStatus"
          placeholder="请选择"
          class="w200"
        >
          <el-option
            v-for="item in dict.type.approval_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="roleList" :height="tableHeight">
      <el-table-column
        label="案件案号"
        prop="caseNo"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="发票抬头"
        prop="title"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="发票金额"
        prop="amount"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="申请人"
        prop="createBy"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column label="审批状态" prop="auditStatus" show-overflow-tooltip
        ><template slot-scope="scope">
          <dict-tag
            :options="dict.type.approval_status"
            :value="scope.row.auditStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="120"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <div v-if="proveType == 1">
            <el-button size="mini" type="text" @click="onview(scope.row)"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="onapply(scope.row)"
              v-if="scope.row.auditStatus != 1"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="text"
              v-if="scope.row.auditStatus != 1"
              @click="ondel(scope.row)"
              >删除</el-button
            >
          </div>
          <div v-else-if="proveType == 2">
            <el-button size="mini" type="text" @click="onview(scope.row)"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="onview(scope.row, 1)"
              v-if="scope.row.auditStatus != 1"
              >审批</el-button
            >
          </div>
          <div v-else>
            <el-button
              size="mini"
              type="text"
              @click="onview(scope.row)"
              v-hasPermi="['myinvocies:view']"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              v-hasPermi="['myinvocies:edit']"
              @click="onapply(scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="ondel(scope.row)"
              v-hasPermi="['myinvocies:del']"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <caseModal ref="detailModalVue" />
  </div>
</template>

<script>
import { listRole, delRole } from "@/api/system/role";
import { invoicelist, invoicedel } from "@/api/case/case";

import caseModal from "./caseModal.vue";
import { number } from "echarts";
export default {
  name: "manage",
  components: {
    caseModal,
  },
  dicts: [
    "customer_state",
    "approval_status",
    "unit",
    "person",
    "category_id",
    "customer_industry",
  ],
  computed: {
    tableHeight() {
      return this.$store.state.app.clientHeight;
    },
  },
  props: {
    proveType: { // 0 为发票管理，1为我的发票，2为审批管理
      type: String,
      default: "1"
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 角色表格数据
      roleList: [],
      total: 1, //总条数
      dateRange: [], //搜索时间
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        caseNo: "",
        title: "",
        auditStatus: "",
        orderByColumn: "id",
        // isAsc: "desc",
        proveType: this.proveType,
      },
    };
  },
  created() {
    this.getList();
    this.$root.$on("notice:customer", (e) => {
      console.log("on notice:customer", e);
      this.$nextTick(() => {
        this.onview(e);
      });
    });
  },
  mounted() {},
  methods: {
    onAdd() {
      this.$router.push({
        path: "/financial/addInvoices",
      });
    },
    formatter(row) {
      switch (row.roleSort) {
        case 1:
          return "正常";
        case 2:
          return "不正常";
        default:
          return row.roleSort;
      }
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      invoicelist(this.queryParams).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //删除
    ondel(row) {
      console.log(row);
      let that = this;
      this.$modal.confirm(`是否确认删除${row.caseNo}`).then(function () {
        invoicedel(row.id).then((res) => {
          that.$modal.msgSuccess("删除成功");
          that.getList();
        });
      });
    },
    //详情
    onview(row, examine) {
      this.$router.push({
        path: "/financial/addInvoices",
        query: { id: row.id, type: "view", examine },
      });
    },
    //添加编辑
    onapply(row) {
      this.$router.push({
        path: "/financial/addInvoices",
        query: { id: row.id, type: "edit" },
      });
    },
  },
};
</script>
<style scoped lang="scss">
.w200 {
  width: 150px;
}
.appaybtn {
  float: right;
}
</style>
